/*
 * @lc app=leetcode.cn id=917 lang=swift
 *
 * [917] 仅仅反转字母
 */

// @lc code=start
class Solution {
    func reverseOnlyLetters(_ s: String) -> String {
        var characters = Array(s)
        var left = 0, right = characters.count - 1
        while left < right {
            if characters[left].isLetter && characters[right].isLetter {
                (characters[left], characters[right]) = (characters[right], characters[left])
                left += 1
                right -= 1
            }else if characters[left].isLetter == false {
                left += 1
            }else{
                right -= 1
            }
        }
        return String(characters)
    }
}
// @lc code=end

